<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "mall_publisher".
 *
 * @property int $id
 * @property string $name 名称
 * @property string $avatar_url 头像
 * @property int $status -1禁用 1启用
 * @property int $create_time 创建时间
 */
class MallPublisher extends \yii\db\ActiveRecord
{

    //定义场景
    const SCENARIO_DEFAULT = 'default';
    const SCENARIO_UPLOAD = 'upload';

    public $file;

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'mall_publisher';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name', 'avatar_url', 'create_time'], 'required'],
            [['avatar_url'], 'string'],
            [['file'], 'file'],
            [['status', 'create_time'], 'integer'],
            [['name'], 'string', 'max' => 20],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '名字',
            'avatar_url' => '头像',
            'status' => '状态',
            'create_time' => '时间',
        ];
    }

    public static function attributeValue()
    {
        return [
            'status' => [
                '1' => '启用',
                '-1' => '禁用'
            ],
        ];
    }

    public function getStatus()
    {
        switch($this->status)
        {
            case -1:
                $value = '禁用';
                break;
            case 1:
                $value = '启用';
                break;
            default:
                $value = '未知';
                break;
        }
        return $value;
    }

    public function scenarios()
    {
        $scenarios = parent::scenarios();
        $scenarios[self::SCENARIO_DEFAULT] = ['id', 'name', 'avatar_url', 'status', 'create_time'];
        $scenarios[self::SCENARIO_UPLOAD] = ['file'];
        return $scenarios;
    }
}
